if (window.widget) (function(){
	
  var setPref = widget.setPreferenceForKey;
  var getPref = widget.preferenceForKey;
  
  widget.setPreferenceForKey = function(pref, key)
  {
    return setPref.call(widget, pref.toJSONString(), key);
  };
  
  widget.preferenceForKey = function(key)
  {
    var pref = getPref.call(widget, key);
    if (!pref) return null;
    try {
      pref = ('{"pref":'+pref+'}').parseJSON().pref;
    }
    catch (e)
    {
      opera.postError('Error parsing JSON preference');
      return null;
    }
    return pref;
  };
  
})();